#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStackedWidget>
#include <QTimer>
#include "SudokuBoard.h"
#include "GameManager.h"
#include "LevelManager.h"

class QPushButton;
class QComboBox;
class QLabel;
class QListWidget;
class QListWidgetItem;
class QTextEdit;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void onLevelItemClicked(QListWidgetItem *item);
    void onPuzzleSolved();
    void onNewGame();
    void onShowLevels();
    void onShowProgress();
    void onShowMainMenu();
    void onCellValueChanged(int row, int col, int value);
    void onTimerTimeout();
    void onCheckSolution();
    void onResetBoard();
    void onHintRequested();

private:
    void setupUI();
    void setupMainMenu();
    void setupGameScreen();
    void setupLevelSelectionScreen();
    void setupProgressScreen();
    void updateTimerDisplay();
    void startGame(int levelId);
    void showCongratulations();
    QString formatTime(int seconds) const;
    
    QStackedWidget *m_stackedWidget;
    SudokuBoard *m_sudokuBoard;
    LevelManager *m_levelManager;
    
    // 主菜单
    QWidget *m_mainMenuScreen;
    QPushButton *m_newGameButton;
    QPushButton *m_levelSelectButton;
    QPushButton *m_progressButton;
    QPushButton *m_quitButton;
    
    // 游戏界面
    QWidget *m_gameScreen;
    QLabel *m_timerLabel;
    QLabel *m_levelLabel;
    QLabel *m_difficultyLabel;
    QPushButton *m_checkButton;
    QPushButton *m_resetButton;
    QPushButton *m_hintButton;
    QPushButton *m_menuButton;
    
    // 关卡选择界面
    QWidget *m_levelScreen;
    QListWidget *m_levelList;
    QPushButton *m_levelBackButton;
    
    // 进度界面
    QWidget *m_progressScreen;
    QLabel *m_progressTitle;
    QTextEdit *m_progressText;
    QPushButton *m_progressBackButton;
    QPushButton *m_resetProgressButton;
    
    QTimer *m_gameTimer;
    int m_elapsedTime;
    int m_currentLevelId;
};

#endif
